<template>
  <div id="app">
    <ListCentent :records="records" @sousuo="sousuoFn" @dpy="dpyFn"></ListCentent>
    <ListModel :visible.sync="isShow" :records="records" :newArr="newArr" @del="delFn"></ListModel>
  </div>
</template>

<script>
import ListCentent from './components/ListCentent.vue'
import ListModel from './components/ListModel'
export default {
  name: 'App',
  components: {
    ListModel,
    ListCentent
  },
  data () {
    return {
      isShow: false,
      newArr: [],
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        }
      ],
    }
  },
  methods: {
    delFn () {
      this.isShow = false
    },
    dpyFn (date) {
      this.isShow = true
      this.newArr = this.records.filter(item => item.date === date)
      console.log(this.newArr)
    },
    sousuoFn (name) {
      if (name === '') {
        this.records = [
          {
            date: '2022-01-01',
            doctor: '张三',
            diagnosis: '感冒',
            prescription: '感冒药',
          },
          {
            date: '2022-02-01',
            doctor: '李四',
            diagnosis: '头疼',
            prescription: '止疼药',
          },
          {
            date: '2022-03-01',
            doctor: '王五',
            diagnosis: '腰痛',
            prescription: '止痛贴',
          }
        ]
      } else {
        this.records = this.records.filter(item => item.doctor === name)
      }

    }
  },
}
</script>

<style>
</style>
